#include <stdio.h>
#include <stdlib.h>

#define MaxSize 10

typedef struct
{
    int data[MaxSize];
    int top;
} SqStack;

//初始化栈
void InitStack(SqStack &S)
{
    S.top = -1;
}

bool Push(SqStack &S, int x)
{
    if (S.top == MaxSize - 1)
    {
        return false;
    }
    S.top++;
    S.data[S.top] = x;
    return true;
}

bool Pop(SqStack &S, int &x)
{
    if (S.top == -1)
    {
        return false;
    }
    x = S.data[S.top--];
    return true;
}

bool GetTop(SqStack S, int &x)
{
    x = S.data[S.top];
    return true;
}

/*
共享栈的概念:
有两个栈指针top0,top1
初始化时：top0指向-1，top1指向MaxSize
两个栈共享一个数组，top0=-1表示栈1位空，top1=MaxSize表示栈2为空
两个栈的栈顶向共享数组的中间延伸

栈满条件：(top1-top0==1)
*/

int main()
{
    printf("\n\n========================================================================\n\n");
    SqStack S;
    InitStack(S);
    Push(S, 1);
    Push(S, 3);
    int x1;
    int x2;
    Pop(S, x1);
    Pop(S, x2);
    printf("%d\n", x1);
    printf("%d\n", x2);
    printf("\n\n========================================================================\n\n");
    return 0;
}